package com.ninetaildemonfox.zdl.socialproject.mvp.presenter;

import android.support.v7.app.AppCompatActivity;

import com.google.gson.JsonObject;
import com.hyphenate.easeui.utils.map.JSONUtils;
import com.ninetaildemonfox.zdl.socialproject.config.Constants;
import com.ninetaildemonfox.zdl.socialproject.http.https.Model;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.PrivacySettingCon;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 创建人： Nine tails fox
 * 创建时间： 2019/8/12
 * 功能描述：
 * 联系方式：1037438704@qq.com
 *
 * @author NineTailDemonFox
 */

public class PrivacySettingPresenter {
    private AppCompatActivity me;
    private PrivacySettingCon contract;

    public PrivacySettingPresenter(AppCompatActivity me, PrivacySettingCon contract) {
        this.me = me;
        this.contract = contract;
    }

    public void getSystemSet(String token, String set_info, String set_hidden_list, String set_hidden_distance, String set_info_money, String type) {
        Model.getInstance().getUserApi().getSystemSet(token, set_info, set_hidden_list, set_hidden_distance, set_info_money, type)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null) {
                            return;
                        }
                        Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                        if (type.equals("1")) {
                            if (data == null) {
                                return;
                            }
                            contract.Success(data);
                        } else {
                            ToastUtil.show(map.get("message"));
                            me.finish();
                        }
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {

                    }
                });
    }

}
